package com.wyz.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wyz.mapper.InventoryMapper;
import com.wyz.model.Inventory;
import com.wyz.model.Supplier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author wk
 * @desc
 * @date 2024/7/27 21:40
 */
@Controller
public class InventoryController {
    @Resource
    private InventoryMapper inventoryMapper;
    @RequestMapping("/inventory/getAllInventory")
    public String getAllInventory(HttpSession session) {
        session.setAttribute("inventory", inventoryMapper.selectList(null));
        return "back/stock_control";
    }
    @RequestMapping("/inventory/getInventoryById")
    public String getInventoryById(Integer id,HttpSession session) {
        session.setAttribute("inventory", inventoryMapper.selectById(id));
        return "back/stock_controlView";
    }
    @RequestMapping("/inventory/search.do")
    public String search(String condition,String sort,HttpSession session) {
        QueryWrapper<Inventory> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("inventory_id","%"+condition+"%")
                .or().like("goods_barcode","%"+condition+"%")
                .or().like("instoragePerson_information","%"+condition+"%")
                .or().like("supplierCompany","%"+condition+"%")
                .or().like("goods_name","%"+condition+"%")
                .or().like("goods_sprecification","%"+condition+"%")
                .or().like("inventory_remark","%"+condition+"%")
                .or().like("inventory_num","%"+condition+"%")
                .orderByAsc(sort);
        List<Inventory> inventory = inventoryMapper.selectList(queryWrapper);
        session.setAttribute("inventory",inventory);
        return "back/stock_control";
    }
}
